package yuan.deng.controller;

import yuan.deng.pojo.User;
import yuan.deng.service.UserService;
import yuan.deng.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/user")
public class UserController extends HttpServlet {
    UserService userService=new UserServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");//设置字符集
        resp.setContentType("text/html;charset=utf-8");
        finAll(req,resp);//简单的测试调用,后期与页面交互
        findById(req,resp);
        findByUser(req,resp);
        addUser(req,resp);
    }
    public void finAll(HttpServletRequest req, HttpServletResponse resp){
        List<User> list=userService.finAll();
        System.out.println(list);
    }
    public void findById(HttpServletRequest req, HttpServletResponse resp){
        int id=1;
        User user=userService.findById(id);
        System.out.println(user);
    }
    public void addUser(HttpServletRequest req, HttpServletResponse resp){
        User user=new User(null,"zhang",345);
        int i=userService.addUser(user);
        System.out.println(i);
    }
    public void findByUser(HttpServletRequest req, HttpServletResponse resp){
        User u=new User();
        u.setId(1);
        User user=userService.findByUser(u);
        System.out.println(user);
    }
}
